package redis.inaction.spring.dao;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import redis.inaction.spring.entity.City;

import java.util.HashMap;
import java.util.Map;

/**
 * 本demo纯粹演示redis，数据库操作这里只模拟从cityMap里获取
 */
@Component
@Slf4j
public class CityDao {

    private static Map<String, City> cityMap = new HashMap<>();

    static{
        cityMap.put("110100000000", new City(1L,"110100000000","北京"));
        cityMap.put("310100000000", new City(2L,"310100000000","上海"));
        cityMap.put("440300000000", new City(3L,"440300000000","深圳"));
        cityMap.put("440100000000", new City(4L,"440100000000","广州"));
    }

    public City getCity(String code){
        City city = cityMap.get(code);
        log.info("query city from DB, code {}:, city: {}", code, city);
        return city;
    }
}
